var global = new Vue({
    el: "#global_house",
    data: {
        houseUrl: "api/sys/house/listHouse",
        dictUrl: "api/sys/house/dictInfo",
        menuUrl: "api/sys/index/menuCol",
        menuData:{},
        house: {},
        dictCondition: {},
        parama: {
            pageSize: 12,
            pageNo: 1,
            currentStatus: "",
            areaCondition: "",
            propertyType: "",
            useCondition: ""
        }
    },
    mounted: function () {
        this.initDict();
        this.sendRequest();
        menu_hover();
    },
    methods: {
        initDict: function () {//初始化条件
            var areaType = this.getQueryString("areaCondition");
            if(areaType){
                this.parama.areaCondition = areaType;
            }
            this.$http.get(baseUrl + this.dictUrl).then(
                function (res) {
                    this.dictCondition = res.data.data;
                }
            ).catch(function (response) {
                console.log(response)
            })
        },
        queryHouseByCondition: function (value, type) {
            if (type == 1) {
                this.parama.currentStatus = value;
            } else if (type == 2) {
                this.parama.areaCondition = value;
            } else if (type == 3) {
                this.parama.propertyType = value;
            } else if (type == 4) {
                this.parama.useCondition = value;
            }
            this.parama.pageNo = 1;
            this.sendRequest();
        },
        sendRequest: function () {
            this.$http.get(baseUrl + this.houseUrl+"?"+this.formatParama(this.parama)).then(
                function (res) {
                    this.house = res.data.data;
                    this.toTop();
                }
            ).catch(function (response) {
                console.log(response)
            })

            this.$http.get(baseUrl + this.menuUrl).then(
                function (res) {
                    this.menuData = res.data.data;
                }
            ).catch(function (response) {
                console.log(response)
            })
        },
        formatParama:function (parama) {
            var result ="";
            for(var key in parama){
                result += key +"="+parama[key]+"&";
            }
            return result.substring(0,result.length-1);
        },
        pageQuery:function (pageNo) {//分页
            if(pageNo == this.parama.pageNo){
                return;
            }
            this.parama.pageNo = pageNo;
            this.sendRequest();
        },
        toTop:function () {
            $('html,body').animate({scrollTop: '0px'}, 800);
        },
        getQueryString:function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    }
})